﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PECommon
{
    /// <summary>
    /// 服务抽象进程，便于多个模块继承使用
    /// </summary>
    public abstract class ServerProcess<T> : ILogic where T : new()
    {
        private static T instance;
        public static T Instance { get { instance ??= new(); return instance; } }

        public int ProcessID;
        private readonly List<ILogic> mLogics = new List<ILogic>();
        public virtual void Awake()
        {
            for (int i = 0; i < mLogics.Count; i++)
            {
                mLogics[i].Awake();
            }
        }

        public virtual void Destory()
        {
            for (int i = 0; i < mLogics.Count; i++)
            {
                mLogics[i].Destory();
            }
        }

        public virtual void Update()
        {
            for (int i = 0; i < mLogics.Count; i++) { mLogics[i].Update(); }
        }

        public void AddSvcAndSys(ILogic logic)
        {
            mLogics.Add(logic);
        }

        public abstract void HandleConsoleCMD(ConsoleCMD cMD, string? cmd);
    }
}
